home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / apps / astronmy / strchart.arc / patch.arc / starst.c < prev   
C/C++ Source or Header  |  1989-03-23  |  18KB  |  578 lines

  1. /*
  2. ** Atari ST driver for starchart.
  3. ** Works on color systems only, compiled with Mark Williams C.
  4. ** Written by Dave Yearke (dgy@sigmast), September 1988.
  5. ** Portions of this program (c) Mark Williams Company.
  6. ** Thanks to the authors of the other starchart drivers for giving
  7. ** me some examples to work from.
  8. */
  9.  
  10. extern int exit_and_save;
  11. extern char *getenv(), picturefile[];
  12.  
  13. #include <ctype.h>    /* isprint(), iscntrl(), etc. */
  14. #include <linea.h>    /* Line A (low-level graphics) routines. */
  15. #include <osbind.h>   /* Operating system bindings */
  16. #include <vdibind.h>  /* The virtual device interface routines */
  17. #include <xbios.h>    /* Extended BIOS bindings */
  18. #include "starchrt.h" /* Starchart information */
  19.  
  20. /* Global line A variables used by vdi; MUST be included */
  21. int contrl[12], intin[128], ptsin[128], intout[128], ptsout[128];
  22. /* Array used by vs_clip() */
  23. int cliparray[] = { 1, 1, 319, 199 };
  24. /* Arrays used by v_opvwk() */
  25. int work_in[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2 };
  26. int work_out[57];
  27.  
  28. #define TRUE 1
  29. #define NULL 0
  30.  
  31. /*
  32. ** Starchart was designed for 1024x768 pixels.  These macros scale the
  33. ** image to the 320x200 Atari ST low-resolution (16-color) mode.  Also,
  34. ** the y coord is subtracted from 200 so the image isn't upside-down.
  35. */
  36. #define xadjust(x) ((x) * 0.3125)
  37. #define yadjust(y) (200 - ((y) * 0.2604167))
  38.  
  39. struct la_font *fontp; /* Line A font header. */
  40. char line[100], linemode, *p;
  41. char scr_wrk[1024];
  42. int vdihandle; /* Virtual device's handle */
  43.  
  44. int CURRX, CURRY, currez, old_color[16], oldrez = 99; /* 99 is impossible! */
  45.  
  46. /*
  47. ** Settings for the palette, given as RGB, 3 bits for each color (512 total).
  48. ** I tried to use different registers for different types of objects so they
  49. ** could be set individually (for example, in DEGAS you could blink a register
  50. ** for an object you're trying to point out).
  51. */
  52. int new_color[16] = { 0x000,   /* Black      - Background color */
  53.                       0x777,   /* White      - 1st and higher mag. stars */
  54.                       0x666,   /* White      - 2nd mag. stars */
  55.                       0x555,   /* White      - 3rd mag. stars */
  56.                       0x444,   /* White      - 4th mag. stars */
  57.                       0x333,   /* White      - 5th mag. stars */
  58.                       0x222,   /* White      - 6th and lower mag. stars */
  59.                       0x222,   /* White      - Nebulae, Galaxies, Clusters */
  60.                       0x007,   /* Blue       - 1st and higher mag. stars */
  61.                       0x700,   /* Red        - 1st and higher mag. stars */
  62.                       0x770,   /* Yellow     - Sol */
  63.                       0x704,   /* Pink       - Inferior Planets */
  64.                       0x404,   /* Purple     - Superior Planets */
  65.                       0x020,   /* Dark Green - Dotted lines */
  66.                       0x200,   /* Dark Red   - Hyphenated lines */
  67.                       0x003 }; /* Deep Blue  - Text and borders */
  68.  
  69. /*
  70. ** These are reverse-image colors for the background and stars, used when the
  71. ** 'r' key is hit when the program pauses before exiting.  Switching these
  72. ** registers makes a nice output image for a screen dump to a printer.
  73. */
  74. int rev_color[8]  = { 0x777,   /* White      - Background color */
  75.                       0x000,   /* Black      - 1st and higher mag. stars */
  76.                       0x222,   /* Black      - 2nd mag. stars */
  77.                       0x333,   /* Black      - 3rd mag. stars */
  78.                       0x444,   /* Black      - 4th mag. stars */
  79.                       0x555,   /* Black      - 5th mag. stars */
  80.                       0x666,   /* Black      - 6th and lower mag. stars */
  81.                       0x666 }; /* Black      - Nebulae, Galaxies, Clusters */
  82.  
  83. /*
  84. ** Chart parameters (limiting magnitude and window x,y,w,h)
  85. */
  86.  
  87. mapblock thumbnail =    { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
  88.             3.2, 1.0, 2.05, 420, 35, 480, 195, 0.0 };
  89.  
  90. mapblock master =    { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
  91.             8.0, 2.0, 2.05, 20, 265, 880, 500, 0.0 };
  92.  
  93. mapblock bigmaster =    { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
  94.             8.0, 2.5, 2.5, 20,  65, 880, 700, 0.0 };
  95.  
  96. /*
  97. ** Generic functions
  98. */
  99.  
  100. /*
  101. ** Initialize the graphics mode
  102. */
  103. vecopen()
  104. {
  105.      int i;
  106.  
  107.      Cconws("\033H\033J"); /* Clear the screen */
  108.      if ((oldrez = Getrez()) == GR_HIGH) {
  109.           die("%s\n", "Sorry, this works on color systems only.");
  110.           Pterm(1);
  111.      } else if (oldrez == GR_MED)
  112.           Setscreen((char *)-1, (char *)-1, GR_LOW); /* Set low resolution */
  113.      currez = GR_LOW;
  114.      appl_init(); /* Initialize the application and register it with AES */
  115.      vdihandle = graf_handle(&i, &i, &i, &i); /* Get a VDI handle */
  116.      v_opnvwk(work_in, &vdihandle, work_out); /* Open the virtual workscreen */
  117.      vs_clip(vdihandle, 1, cliparray); /* Set the clipping rectangle */
  118.      for (i = 0; i < 16; i++) /* Save and set the palette */
  119.           old_color[i] = Setcolor(i, new_color[i]);
  120.  
  121.      linea0(); /* Initialize the line A routines */
  122.      lineaa(); /* Hide mouse pointer */
  123.      Cursconf(0, 0); /* Hide cursor */
  124.  
  125.      WMODE = 0; /* Writing mode = replace */
  126.      STYLE = 0; /* Normal Letters */
  127.      SRCY = 0; /* Y coord of character in font */
  128.      LITEMSK = 0x5555; /* Lightening and skewing masks for text */
  129.      SKEWMSK = 0x1111;
  130.      TEXTFG = 15; /* Text foreground dark blue */
  131.      SCRTCHP = scr_wrk; /* Scratch area for graphics */
  132.      LNMASK = -1; /* Solid lines */
  133.      WEIGHT = 1; /* Thickening factor for lines */
  134.      LSTLIN = -1;
  135. }
  136.  
  137. /*
  138. ** Clean up
  139. */
  140. vecclose ()
  141. {
  142.      register int i;
  143.  
  144.      if (exit_and_save)
  145.           savepic();
  146.      else
  147.           while (1) { /* Loop if 'r' is pressed, return for anything else */
  148.                switch (i = Crawcin()) { /* Wait for keypress before quitting */
  149.                case 'r': /* Reverse the color registers */
  150.                     if (Setcolor(0, -1) == 0) { /* If normal, reverse it */
  151.                          for (i = 0; i < 8; i++)
  152.                               Setcolor(i, rev_color[i]);
  153.                     } else { /* Make it normal */
  154.                          for (i = 0; i < 8; i++)
  155.                               Setcolor(i, new_color[i]);
  156.                     }
  157.                     continue; /* Restart the loop */
  158.                     break;
  159.                case 's': /* Save as a DEGAS picture */
  160.                     strcpy(picturefile, "star.pi1");
  161.                     savepic();
  162.                     break;
  163.                case 'S': /* Save as a NeoChrome picture */
  164.                     strcpy(picturefile, "star.neo");
  165.                     savepic();
  166.                     break;
  167.                default:
  168.                     break;
  169.                }
  170.                break;
  171.           }
  172.      vecreset();
  173. }
  174.  
  175. /*
  176. ** Restore the screen
  177. */
  178. vecreset()
  179. {
  180.      int i;
  181.  
  182.      v_clsvwk(vdihandle); /* Close the virtual workscreen */
  183.      appl_exit(); /* Remove the application from AES */
  184.      Cconws("\033H\033J"); /* Clear the screen */
  185.      Setscreen((char *)-1, (char *)-1, oldrez); /* Set resolution */
  186.      for (i = 0; i < 16; i++) /* Set the colors back to their saved values */
  187.           Setcolor(i, old_color[i]);
  188.      if (((getenv("PATH")) == 0) || (strlen(getenv("PATH")) == 0))
  189.           linea9(); /* Show mouse pointer */
  190.      else /* If called from a shell */
  191.           Cursconf(1, 0); /* Show cursor */
  192. }
  193.  
  194. /*
  195. ** Save the screen as a DEGAS or NeoChrome picture
  196. */
  197. savepic()
  198. {
  199.      int neo = 0, file; /* Assume DEGAS file */
  200.  
  201.      if (strrchr(picturefile, '.') != NULL) { /* Extender given */
  202.           if ((!strncmp(picturefile + strrchr(picturefile, '.'), ".neo", 4)) ||
  203.              (!strncmp(picturefile + strrchr(picturefile, '.'), ".NEO", 4)))
  204.                ++neo; /* Save as a NeoChrome picture */
  205.      } else
  206.           strcat(picturefile, ".pi1");
  207.      if ((file = creat(picturefile, 0)) == -1)
  208.           die("Cannot open %s.", picturefile);
  209.      if (neo) /* NeoChrome has two extra null bytes at the beginning */
  210.           if (write(file, &currez, 2) != 2)
  211.                die("Write failure on file %s.", picturefile);
  212.      if (write(file, &currez, 2) != 2) /* Write the resolution */
  213.           die("Write failure on file %s.", picturefile);
  214.      if (write(file,